/** LICENCE
 *
 * SteamGifts Groups Addon
 * Copyright (c) 2012-2013 nomadbr  <vini.rs@gmail.com>
 * http://steamgifts-groups.googlecode.com
 *
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 *
 */
/**
 * @function steamgifts-groups
 * @author nomadbr
 * @source http://steamgifts-groups.googlecode.com/
 */
(function ($) {
    $.fn.reverse = [].reverse;
    /**
     * @function lscache
     * @author pamelafox
     * @source https://github.com/pamelafox/lscache
     */
    if (typeof lscache != 'function') {
    	var lscache=function(){function f(){var e="__lscachetest__";var t=e;if(s!==undefined){return s}try{d(e,t);v(e);s=true}catch(n){s=false}return s}function l(){if(o===undefined){o=window.JSON!=null}return o}function c(e){return e+t}function h(){return Math.floor((new Date).getTime()/r)}function p(t){return localStorage.getItem(e+u+t)}function d(t,n){localStorage.removeItem(e+u+t);localStorage.setItem(e+u+t,n)}function v(t){localStorage.removeItem(e+u+t)}function m(e,t){if(!a)return;if(!"console"in window||typeof window.console.warn!=="function")return;window.console.warn("lscache - "+e);if(t)window.console.warn("lscache - The error was: "+t.message)}var e="lscache-";var t="-cacheexpiration";var n=10;var r=60*1e3;var i=Math.floor(864e13/r);var s;var o;var u="";var a=false;return{set:function(r,s,o){if(!f())return;if(typeof s!=="string"){if(!l())return;try{s=JSON.stringify(s)}catch(a){return}}try{d(r,s)}catch(a){if(a.name==="QUOTA_EXCEEDED_ERR"||a.name==="NS_ERROR_DOM_QUOTA_REACHED"||a.name==="QuotaExceededError"){var g=[];var y;for(var b=0;b<localStorage.length;b++){y=localStorage.key(b);if(y.indexOf(e+u)===0&&y.indexOf(t)<0){var w=y.substr((e+u).length);var E=c(w);var S=p(E);if(S){S=parseInt(S,n)}else{S=i}g.push({key:w,size:(p(w)||"").length,expiration:S})}}g.sort(function(e,t){return t.expiration-e.expiration});var x=(s||"").length;while(g.length&&x>0){y=g.pop();m("Cache is full, removing item with key '"+r+"'");v(y.key);v(c(y.key));x-=y.size}try{d(r,s)}catch(a){m("Could not add item with key '"+r+"', perhaps it's too big?",a);return}}else{m("Could not add item with key '"+r+"'",a);return}}if(o){d(c(r),(h()+o).toString(n))}else{v(c(r))}},get:function(e){if(!f())return null;var t=c(e);var r=p(t);if(r){var i=parseInt(r,n);if(h()>=i){v(e);v(t);return null}}var s=p(e);if(!s||!l()){return s}try{return JSON.parse(s)}catch(o){return s}},remove:function(e){if(!f())return null;v(e);v(c(e))},supported:function(){return f()},flush:function(){if(!f())return;for(var t=localStorage.length-1;t>=0;--t){var n=localStorage.key(t);if(n.indexOf(e+u)===0){localStorage.removeItem(n)}}},setBucket:function(e){u=e},resetBucket:function(){u=""},enableWarnings:function(e){a=e}}}()
    }

    lscache.setBucket('sgg');

    var unsafeWindow = this['unsafeWindow'] || window,
        addon = {
            'version': '0.1-ALHPA'
        },
        key = 'C2CE5574C85C2158D63384CCB2ED7DEA',
        user = {
            'loggedIn': false,
            'steamID': '',
            'points': 0,
            'steamID64': '',
        },
        image = {
            'loading': '',
        },
        locationURI = window.location.href.split(/[\/#\?]+/),
        page = {
            'section': locationURI[2],
            'id': locationURI[3],
            'name': locationURI[4],
            'number': 1,
            maxItemsPerPage: {
                'default': 40,
                'topic': 40,
                'giveaway': 40,
                'forum': 40
            },
            'maxPages': 1
        },
        configCache = {},
        now = Date.now();

    if (page['name'] === null || $.trim(page['name']) === '') {
        page['name'] = 'name';
    }

    if (page['id'] === null) {
        page['id'] = 'id';
    }

    if ($('.numbers>.selected:first').length) {
        page['number'] = parseInt($('.numbers>.selected:first').text(),10);
    }

    //Initialize.
    groupInit();

    //Control panel links.
    if (user['loggedIn']) {
        $('ul:contains(View Profile):first', '#navigation').append('<li><a href="/steamgiftsgroups">SteamGifts Groups</a></li>');
    } else {
        $('li:contains(Forum)', '#navigation').after('<li><a href="/steamgiftsgroups">SteamGifts Groups</a></li>');
    }
    $('div.right', '.footer_sm').prepend('<a href="/steamgiftsgroups" style="margin-right:15px;">SteamGifts Groups</a>');

    //Page specific stuff.
	switch (page['section']) {
		case 'steamgiftsgroups':
			alert("Under Construction!");
		break;
		case 'create':
			doGroupCreate();
		break;
	}

    //Update notification.
    if (lscache.get('addonLastVersion') !== addon['version']) {
        lscache.set('addonLastVersion', addon['version']);
    }

    /**
     * Initialize user.
     */



    function groupInit() {
        if ($('a:contains(View Profile)', '#navigation').length) {
            user['loggedIn'] = true;
            user['steamID'] = $('a:contains(View Profile)', '#navigation').attr('href').match('[^\/]*$')[0];
            user['points'] = parseInt($('a:contains(Account)', '#navigation').text().trim().replace(/([^0-9]*)/g, ''), 10);
            $.getJSON('http://api.steampowered.com/ISteamUser/ResolveVanityURL/v0001/?key='+key+'&vanityurl='+user['steamID'], function(data) {
                console.log('ID64: '+data.steamid);
            });

            /*$.get("http://www.steamgifts.com/user/" + user['steamID'], {}, function(data) {
                obj = $(data);
            }).complete(function() {
                if ($('.profile', obj).length) {
                    htmldata = $('.details', obj).find('a:first').attr('href').split('/');
                    user['steamID64'] = htmldata[4];
                }
                console.log(user);
                console.log(page);
            });
            */
        }
    }

    function doGroupCreate() {
		$('.group_id').css({width: '512px'});
		$('.group_id').before('<a href="#" class="find_owners button" style="display: inline-block; margin-left:5px;float: right;margin-top: -8px; width: 59px; display: none;">Verify users</a>');
		$('.group_id').after('<div class="clear_both"></div><div class="players date_description" style="width: 881px; display: none;"></div>');
        $('.checkbox').click(function(){
			if ($(this).hasClass('display_groups') && $(this).hasClass('selected')) {
				$('.find_owners').show();
			} else {
				$('.find_owners').hide();
			}
		});
        $('.find_owners').click(function(event) {
            var selected = {
                    group : {
                        'label' : 'Selected Group:',
                        'id' : $('.group_id').val(),
                        'name' : $('.group_id').text(),
                        'shortName' : '',
                    },
                    gift : {
                        'label' : 'Selected Gift:',
                        'id' : $('.game_id').val(),
                        'name' : $('.game_id').text(),
                    }
                };
                userUrl = 'http://steamcommunity.com/groups/XXXX/memberslistxml/?xml=1';
                console.log(selected);
                //data = '<strong>Game:</strong>';
                // data += '<p class="mambers"><img src="' + image["loading"] + '" /></p>';
                //$.get('http://steamcommunity.com/openid/id/' + user['username'][0] + '/?xml=1', function(xml){
                //   console.log( $.parseXML('http://steamcommunity.com/id/' + user['username'][0] + '/?xml=1') );
                //});
                /*
            if($('.players')){
                $('.players').html(data);

                $('.players').show();
            }
            */
            return false;
        });
	}

    /**
     * SteamGifts Groups - Control Panel
     */

    function doGroupControlPanel() {
        //Retitle.
        $('title').text('SteamGifts Groups ' + addon["version"] + ' Control Panel');

        //Remove homepage content.
        $('.bg_gradient.shadow').removeClass('shadow');
        $('.content:has(.featured)').remove();
        $('.search', '#navigation').replaceWith('<div class="search disabled"></div>');

        //Replace homepage content with our settings page.
        $('.content', '.wrapper').replaceWith('<div class="register" style="width:700px"><div class="invites"><div class="input" style="padding:0px;"><div class="title"><a href="https://code.google.com/p/steamgifts-groups/' + (configGet('f_newestfirst') ? '31337/' : '1/') + '" style="color: #4F565A; text-decoration: none;"><img src=' + image["icon16"] + ' /> SteamGifts Groups ' + addon["version"] + ' Control Panel</a></div><div class="title important" style="float:right;margin-top:0;font-size: 12px;"><a href="" class="sgpMenu" id="sgpCP_Changelog">View changelog</a></div><div class="clear_both"></div></div><div class="divider"></div>');
        /*
		//Menu
		$('.invites', '.wrapper').append('<a class="button sgpMenu" id="sggCP_GroupDetails" href="" style="margin-left:5px;">General Preferences</a><a class="button sgpMenu" id="sgpCP_GiveawayPreferences" href="" style="margin-left:5px; width:120px;">Giveaway Preferences</a><a class="button sgpMenu" id="sgpCP_ForumPreferences" href="" style="margin-left:5px;">Forum Preferences</a><a class="button sgpMenu" id="sgpCP_UserPreferences" href="" style="margin-left:5px;">User Preferences</a><a class="button sgpMenu" id="sgpCP_AdvancedOptions" href="" style="margin-left:5px;">Advanced Options</a><div class="clear_both"></div><div class="divider"></div>');

		//General settings.
		$('<div class="sgpPage" id="sgpCP_GeneralPreferences">\
		<div class="input" style="padding:0 0 8px 0;"><div class="title">General Preferences</div><div class="clear_both"></div></div>\
		<div class="important"><div class="sgpCheckbox" id="ge_notifyupdate"> Update Notifications</div> - Notifies you when the addon has automatically updated.</a></div>\
		<div class="important"><div class="sgpCheckbox" id="ge_highlightunread"> Track New Comments</div> - Tracks and highlights new comments since you viewed the page.</div>\
		<div class="important"><div class="sgpCheckbox" id="ge_comments_ids"> Comment #IDs</div> - Enables comment #IDs which you can direct link to other users.</div>\
		<div class="important"><div class="sgpCheckbox" id="ge_comments_highlightop"> Highlight OP</div> - Highlights all comments by the original poster (OP).</div>\
		<div class="important"><div class="sgpCheckbox" id="ge_floatdown_menu"> Float Down Menu</div> - Keeps the SteamGifts navigation menu always on your screen.</div>\
		<div class="important"><div class="sgpCheckbox" id="ge_comments_imagehover"> Hover Images</div> - Displays popup images when hovering over an image link in a comment.</div>\
		<div class="important"><div class="sgpCheckbox" id="ge_be_bettereditor"> Better Comment Editor</div> - Enables the Better Comment Editor.</div>\
		<div class="important" style="margin-left:20px;"><div class="sgpCheckbox" id="ge_be_livepreview"> Live Preview</div> - Previews how your comment will look with formatting as you type it.</div>\
		<div class="important" style="margin-left:20px;"><div class="sgpCheckbox" id="ge_be_formatbuttons"> Format Buttons</div> - Adds buttons to insert markdown formatting into your comment.</div>\
		<div class="important" style="margin-left:20px;"><div class="sgpCheckbox" id="ge_be_newlineparse"> Parse Line Breaks</div> - Automatically converts all line breaks into markdown.</div>\
		</div>').appendTo('.invites', '.wrapper');

		//Giveaway settings
		$('<div class="sgpPage" id="sgpCP_GiveawayPreferences">\
		<div class="input" style="padding:0 0 8px 0;"><div class="title">Giveaway Preferences</div><div class="clear_both"></div></div>\
		<div class="important"><div class="sgpCheckbox" id="gi_endlessscrolling"> Endless Giveaway Scrolling</div> - Automatically loads the next giveaway page when you reach the bottom.</strike></div>\
		<div class="important" style="margin-left:20px;"><div class="sgpCheckbox" id="gi_endlessscrolling_seamless"> Seamless Scrolling</div> - Hides the page # of # messages.</div>\
		<div class="important"><div class="sgpCheckbox" id="gi_highlightwishlist"> Highlight Wishlist Giveaways</div> - Highlights giveaways for items in your wishlist.</div>\
		<div class="important"><div class="sgpCheckbox" id="gi_hidefeatured"> Hide Featured Giveaway</div> - Hides the featured giveaway.</div>\
		<div class="important" style="margin-left:20px;"><div class="sgpCheckbox" id="gi_replacefeatured"> Replace with New from the Forums</div> - Replaces the Featured Giveaway with the New from the Forums box.</div>\
		<div class="important"><div class="sgpCheckbox" id="gi_showwinchance"> Show Chance to Win</div> - Shows you the percentage chance to win.</div>\
		<div class="important"><div class="sgpCheckbox" id="gi_quickview"> Quick View</div> - Clicking on a giveaway\'s logo will open a popup of the giveaway that you can enter and comment from.</div>\
		<div class="important"><div class="sgpCheckbox" id="gi_gridview"> Grid View</div> - Giveaways are displayed in a grid of their game logos for faster browsing.</div>\
		<div class="divider"></div><div class="clear_both"></div>\
		<div class="input" style="padding:0 0 8px 0;"><div class="title">Giveaway Filtering</div><div class="clear_both"></div></div>\
		<div class="important"><div class="sgpCheckbox" id="gi_f_showpublic"> Show All Public</div> <div class="sgpCheckbox" id="gi_f_showgroup"> Show Group</div> <div class="sgpCheckbox" id="gi_f_showentered"> Show Entered</div> <div class="sgpCheckbox" id="gi_f_contributor_green"> Show Green</div> <div class="sgpCheckbox" id="gi_f_contributor_red"> Show Red</div> <div class="sgpCheckbox" id="gi_f_limitpoints"> Limit by Points (P) Available</div>\
		<div class="important"><div class="sgpCheckbox" id="gi_f_wishlistonly"> Show Wishlist Only</div> <div class="sgpCheckbox" id="gi_f_dlc"> Hide DLC for games I don\'t own</div> <div class="sgpCheckbox" id="gi_f_entrylimit_enabled"> Entry Limit</div> (<div class="sgpCheckbox" id="gi_f_entrylimit_percopy"> Per Copy</div>) <strong style="color:#4F565A;"><input class="sgpFilterInput" id="gi_f_entrylimit_value" type="text" size="5" value="0" maxlength="5" style="margin-top:0;"> </strong></div>\
		<div class="important" style="margin-top: 0px;"><strong style="color:#4F565A;">Minimum Copies: <input class="sgpFilterInput" id="gi_f_minimumcopies" type="text" size="5" value="0" maxlength="5" style="margin-top:0;"> Minimum Win Chance: <input class="sgpFilterInput" id="gi_f_minimumchance" type="text" size="5" value="0" maxlength="5" style="margin-top:0;">%</strong></div>\
		<div class="important" style="color:#4F565A;">$ <input class="sgpFilterInput" id="gi_f_contributor_value_min" type="text" size="7" value="0" maxlength="7" style="margin-top:0;"> <div style="margin-top: 5px; margin-left: 5px; margin-right: 5px; width: 510px; display: inline-block;" id="sgpContributorValueRangeSlider"></div> $ <input class="sgpFilterInput"id="gi_f_contributor_value_max" type="text" size="7" value="0" maxlength="7" style="margin-top:0;"></div>\
		<div class="divider"></div><div class="clear_both"></div>\
		<div class="important"><div class="sgpCheckbox" id="gi_f_enabled"> Custom Filters</div> - Add games or partial game names to filter. <i>Case insensitive. Use * as a wildcard.</i></div>\
		<input type="text" class="sgpInput" id="sgpFilteredGamesAddFilter" name="Giveaway name to filter. Case Insensitive." value="Giveaway name to filter. Case Insensitive." size="50"> <a class="sgpAddListItem" id="sgpFilterGame" href="" style="color:#FFFFFF;"">Add to Filter</a>\
		<div class="relative_dropdown" style="width:150px; padding-top:7px;"><div class="absolute_dropdown" style="width:150px;"><div class="heading" style="font-size:12px; margin-top:1px; margin-bottom:1px;"><a href="" style="padding-left:15px; padding-right:25px;">Import / Export</a></div><div class="items" style="display: none;"><div class="item" style="cursor:pointer;"><a id="sgpFilterExportSGP">Export SteamGifts Plus</a></div><div class="item" style="cursor:pointer;"><a id="sgpFilterImportSGP">Import SteamGifts Plus</a></div><div class="item" style="cursor:pointer;"><a id="sgpFilterImportSGE">Import Zo\'s Addon (SGE)</a></div></div></div></div>\
		<div class="sgpFilteredGamesList" style="margin-top:10px;"></div>\
		<div class="important"><div class="sgpCheckbox" id="gi_f_library_enabled"> Library Filters</div> - Filters games in your library. <i>Filtering for specific library games can enabled or disabled.</i><br><strong style="color:#DD7070;"><img style="margin-bottom:-3px;" src="http://www.steamgifts.com/img/bullet_reported.png"><a href="http://www.steamgifts.com/filter">SteamGifts Filter</a> must be disabled to use SteamGifts Plus Library Filtering.</strong></div>\
		<div class="sgpFilteredGamesListLibrary" style="margin-top:10px;"></div>\
		</div>').appendTo('.invites', '.wrapper').hide();

		$('.sgpFilteredGamesList').append('<div id="sgpFilteredGamesListCustom"></div><div class="divider" style="margin-bottom: 0;"></div><div class="clear_both"></div>');

		$('.sgpFilteredGamesListLibrary').append('<div class="divider" style="margin-bottom: 7px;"></div><div class="important"><strong style="color:#4F565A;"><span style="color: #8BBA65;"><img style="margin-bottom: -2px; width: 12px; height: 12px;" src="http://www.steamgifts.com/img/verify_success.png"> Enabled</span> Library Filters</strong></div><div class="clear_both"></div>\
		<div id="sgpFilteredGamesListLibraryEnabled"></div></div><div class="divider" style="margin-bottom: 0;"></div><div class="clear_both"></div>\
		<div class="important"><strong style="color:#4F565A;"><span style="color: #DD7070;"><img style="margin-bottom: -2px; width: 12px; height: 12px;" src="http://www.steamgifts.com/img/verify_error.png"> Disabled</span> Library Filters</strong></div><div class="clear_both"></div>\
		<div id="sgpFilteredGamesListLibraryDisabled"></div>');

		//Forum settings
		$('<div class="sgpPage" id="sgpCP_ForumPreferences">\
		<div class="input" style="padding:0 0 8px 0;"><div class="title">Forum Preferences</div><div class="clear_both"></div></div>\
		<div class="important"><div class="sgpCheckbox" id="f_endlessscrolling"> Endless Forum Scrolling</div> - Automatically loads the next page in forums and topics when you reach the bottom.</div>\
		<div class="important" style="margin-left:20px;"><div class="sgpCheckbox" id="f_endlessscrolling_seamless"> Seamless Scrolling</div> - Hides the page # of # messages.</div>\
		<div class="important"><div class="sgpCheckbox" id="f_markreplied"> Mark Topics You\'ve Replied To</div> - Marks topics you have replied to with a lighter background and a blue asterisk.</div>\
		<div class="important"><div class="sgpCheckbox" id="f_newestfirst"> Newest Comment First</div> - Orders comments in a topic by newest comment first.</div>\
		<div class="important"><div class="sgpCheckbox" id="f_highlightstafftopics"> Highlight Topics Created by SteamGifts Staff</div> - Highlights all topics created by SteamGifts staff.</div>\
		</div>').appendTo('.invites', '.wrapper').hide();

		//User settings
		$('<div class="sgpPage" id="sgpCP_UserPreferences">\
		<div class="input" style="padding:0 0 8px 0;"><div class="title">User Preferences</div><div class="clear_both"></div></div>\
		<div class="important"><div class="sgpCheckbox" id="u_awards"> User Badges</div> - Show user badges on profiles. <a id="sgpViewAllBadges" href="">View all Badges</a></div><div class="divider"></div>\
		<div class="important"><strong style="color:#4F565A;">Tagged Users</strong> - Tag a user with a nickname or short note to display next to their name.</div>\
		<input type="text" class="sgpInput" id="sgpTaggedUsersAddUsername" name="Username to tag. Case Insensitive." value="Username to tag. Case Insensitive." size="40"><div class="sgpDropdownTextboxRelative"><div class="sgpDropdownTextboxAbsolute"><div class="sgpDropdownTextboxHeading"><a href=""><img src=http://www.steamgifts.com/img/dropdown_arrow.png /></a></div><div class="sgpDropdownTextboxItems" style="display: none;"><div class="sgpDropdownTextboxItem" style="cursor:pointer;"><a style="color:#8BBA65;" href="" class="sgpDropdownTextboxItem">Green</a></div><div class="sgpDropdownTextboxItem" style="cursor:pointer;"><a style="color:#dd7070;" href="" class="sgpDropdownTextboxItem">Red</a></div><div class="sgpDropdownTextboxItem" style="cursor:pointer;"><a style="color:#579AD4;" href="" class="sgpDropdownTextboxItem">Blue</a></div><div class="sgpDropdownTextboxItem" style="cursor:pointer;"><a style="color:#A85ACF;" href="" class="sgpDropdownTextboxItem">Purple</a></div><div class="sgpDropdownTextboxItem" style="cursor:pointer;"><a style="color:#F67FFF;" href="" class="sgpDropdownTextboxItem">Pink</a></div><div class="sgpDropdownTextboxItem" style="cursor:pointer;"><a style="color:#FF8A00;" href="" class="sgpDropdownTextboxItem">Orange</a></div><div class="sgpDropdownTextboxItem" style="cursor:pointer;"><a style="color:#636E75;" href="" class="sgpDropdownTextboxItem">Default</a></div></div></div></div> <input type="text" class="sgpInput" id="sgpTaggedUsersAddTag" name="User tag." value="User tag." maxlength="40" style="width:302px; z-index:35; position:relative;"> <a class="sgpAddListItem" id="usertagAdd" href="">Tag User</a><br><div class="sgpTaggedUsersList" style="margin-top:10px;"></div>\
		<div class="divider"></div><div class="important"><strong style="color:#4F565A;">Ignored Users</strong> - Hides all comments, topics and giveaways posted by ignored users. (SteamGifts staff cannot be ignored.)</div>\
		<input type="text" class="sgpInput" id="sgpIgnoredUsersAddUsername" name="Username to ignore. Case Insensitive." value="Username to ignore. Case Insensitive." size="40"> <a class="sgpAddListItem" id="ignoreUserAdd" href="">Ignore User</a><br><div class="sgpIgnoredUsersList" style="margin-top:10px;"></div>\
		</div>').appendTo('.invites', '.wrapper').hide();

		//Advanced
		$('<div class="sgpPage" id="sgpCP_AdvancedOptions">\
		<div class="input" style="padding:0 0 8px 0;"><div class="title">Advanced Options</div><div class="clear_both"></div></div>\
		<div class="important"><strong style="color:#4F565A;"><a id="sgp_AO_DeleteAddonCache" href="">Delete Saved Addon Data</a></strong> - <strong style="color:#DD7070;"><img src="http://www.steamgifts.com/img/bullet_reported.png" style="margin-bottom:-3px;" />This will irreversibly delete all SteamGifts Plus data.</strong></div>\
		<div class="important"><div class="divider"></div><strong style="color:#4F565A;">New Comment Tracker Expiration</strong><div style="float:right;" class="sgpUnreadCommentExpireRange">4 Weeks</div></div><div class="clear_both"></div><div style="margin-top:5px;" id="sgpUnreadCommentExpireSlider"></div><div class="important"><strong style="color:#DD7070;"><img src="http://www.steamgifts.com/img/bullet_reported.png" style="margin-bottom:-3px;" />SteamGifts plus will save more data in cache the higher this is set.</strong></div>\
		<div class="divider"></div><div class="input" style="padding:0 0 8px 0;"><div class="title">Debug</div><div class="clear_both"></div></div>\
		<div class="important"><strong style="color:#4F565A;">Logged in?</strong>: ' + user['loggedIn'] + ' (' + user['username'] + ')</div>\
		<div class="important"><strong style="color:#4F565A;">Now</strong>: ' + now + '</div>\
		<div class="important"><strong style="color:#4F565A;">lastAwardUpdate</strong>: ' + lscache.get('lastAwardUpdate') + ' <a href="" id="sgpForceUpdateAwards">Force Update</a></div>\
		<div class="important"><strong style="color:#4F565A;">lastWishlistUpdate</strong>: ' + lscache.get('lastWishlistUpdate') + ' <a href="" id="sgpForceUpdateWishlist">Force Update</a></div>\
		<div class="important"><strong style="color:#4F565A;">lastLibraryUpdate</strong>: ' + lscache.get('lastLibraryUpdate') + ' <a href="" id="sgpForceUpdateLibrary">Force Update</a></div>\
		<div class="important"><strong style="color:#4F565A;">lastDLCUpdate</strong>: ' + lscache.get('lastDLCUpdate') + ' <a href="" id="sgpForceUpdateDLC">Force Update</a></div>\
		<div class="important"><strong style="color:#4F565A;">localStorage Free Space</strong>: ' + localStorageRemainingSpace() + ' Bytes</div>\
		</div>').appendTo('.invites', '.wrapper').hide();
*/
        //Changelog
        $('<div class="sgpPage" id="sgpCP_Changelog">\
		<div class="input" style="padding:0 0 8px 0;"><div class="title">SteamGifts Plus Changelog</div><div class="clear_both"></div></div>\
		<div class="important"><iframe style="width: 100%; height:400px; background-color: #FFFFFF; border: 1px solid #ECECEC; border-radius: 5px 5px 5px 5px; padding: 5px;" frameborder="0" src="http://steamgifts-groups.googlecode.com/svn/trunk/changelog.txt"></iframe></div>\
		</div>').appendTo('.invites', '.wrapper').hide();

        //Footer
        $('.invites', '.wrapper').append('<div class="divider"></div><div class="important"><center>SteamGifts Groups ' + addon['version'] + ' &copy; 2012-2013 <a href="http://www.steamgifts.com/user/nomadbr">Nomadbr</a><br /><a href="http://steamgifts-groups.googlecode.com/' + (configGet('f_newestfirst') ? '31337/' : '1/') + '">View Source Page</a></center></div>');

        //Initialize Control Panel.
        //controlPanelInit();
    }


    /**
     * Get a URL paramater.
     * @param {string} name The URL paramater to get.
     * @return {string} The paramatar value. Returns null if no value.
     */
  /*  function getURLParameter(name) {
        return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[,""])[1].replace(/\+/g, '%20'))||null;
    }*/
/*
    function get_http(url, callback) {
        var http = new XMLHttpRequest();
        http.onreadystatechange = function () {
            if (this.readyState == 4 && this.status == 200) {
                callback(this.responseText);
            }
        };
        http.open('GET', url, true);
        http.send(null);
    }
*/
    /*
    function getGroups(steamID) {
    console.log('Fetching groups for profile ' + steamID);
    this.fetch('http://steamcommunity.com/profiles/' + steamID + '/groups', function(err, content) {
      if(err) {
        console.log('Groups for ' + steamID + ' -> ' + err);
      } else {
        $ = cheerio.load(content);

        var name = $('h1').text(),
            groups = {};

        $('a.linkTitle').each(function(i, elem) {
          var obj = $(this),
              link = obj.attr('href');

          link = link.substr(link.lastIndexOf('/') + 1);
          groups[link] = {url: link, name: obj.text()};
          return groups;
        });
      }
    });


  }
*/
    /*
import json
response = '{"response": {"players": [{
                                "steamid": "12345",
                                "communityvisibilitystate": 3,
                                "profilestate": 1,
                                "personaname": "aSteamID",
                                "lastlogoff": 1351676021,
                                "profileurl": "http:\/\/steamcommunity.com\/id\/aSteamID\/",
                                "avatar": "http:\/\/media.steampowered.com\/steamcommunity\/public\/images\/avatars\/b2\/b261f66a17bfa6c95b24f8b4c6b58bb3776d57e4.jpg",
                                "avatarmedium": "http:\/\/media.steampowered.com\/steamcommunity\/public\/images\/avatars\/b2\/b261f66a17bfa6c95b24f8b4c6b58bb3776d57e4_medium.jpg",
                                "avatarfull": "http:\/\/media.steampowered.com\/steamcommunity\/public\/images\/avatars\/b2\/b261f66a17bfa6c95b24f8b4c6b58bb3776d57e4_full.jpg",
                                "personastate": 4,
                                "realname": "Real Name",
                                "primaryclanid": "103582791429705688",
                                "timecreated": 1250966723,
                                "loccountrycode": "GB"
                                }]}}'
data = json.loads(response)
for player in data["response"]["players"]:
    # add code to get game count by player here
    # set to zero for this example
    totalgames = 0
    player["totalgames"] = totalgames

print json.dumps(data, sort_keys=True, indent=4)
*/
    /*
url de GAMES por profile
http://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?key=C2CE5574C85C2158D63384CCB2ED7DEA&steamid=76561197991735931&format=json

url de GAME por profile
http://api.steampowered.com/ISteamUserStats/GetUserStatsForGame/v0002/?appid=202970&key=C2CE5574C85C2158D63384CCB2ED7DEA&steamid=76561197991735931
*/
})(jQuery);